package com.example.speeddating.test1;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;

public class ImageUploader {
    public static void main(String[] args) {
        // 创建一个长度为7的ArrayList
        List<Map<String, Object>> data = new ArrayList<>();

        // 获取最近一周的日期，并添加到ArrayList中
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

        for (int i = 0; i < 7; i++) {
            // 创建一个HashMap来存储日期和对应的int值
            Map<String, Object> map = new HashMap<>();
            map.put("日期", dateFormat.format(calendar.getTime()));
            map.put("数值", 0);

            // 将HashMap添加到ArrayList中
            data.add(map);

            // 将日期往前推一天
            calendar.add(Calendar.DAY_OF_YEAR, -1);
        }

        // 打印日期和对应的int值
        for (Map<String, Object> map : data) {
            System.out.println("日期：" + map.get("日期") + "，数值：" + map.get("数值"));
        }
    }


    public static void saveImage(String imageUrl, String destinationFile) throws IOException {
        URL url = new URL(imageUrl);
        Path destinationPath = Path.of(destinationFile);
        Files.copy(url.openStream(), destinationPath, StandardCopyOption.REPLACE_EXISTING);
    }
}
